<template>
	<view class='load' v-if="show" catchtouchmove="preventTouchMove">
		<view class='lbox' v-if="statuscode==-1">
			<view class='loader_'>
				<image src="../../static/images/home/load.gif" mode=""></image>
			</view>
			<!-- <text class="tip">数据加载中...</text> -->
		</view>
		<!--网络错误-->
		<view class='lbox network-error' v-else-if="statuscode==201">
			<image class="image" src="../../static/images/img-network-error.png" mode="aspectFit"></image>
			<text class="tip">内容加载失败,请检查网络</text>
			<view class="btn btn-reload" @click="onReloadClick">重新加载</view>
		</view>

		<!--数据不存在-->
		<view class='lbox network-error' v-else-if="statuscode==1100">
			<image class="image" src="../../static/images/img-data-error.png" mode="aspectFit"></image>
			<text class="tip">访问的数据不存在或已删除</text>
			<view class="btn btn-reload" @click="onReloadClick">重新加载</view>
		</view>

		<view class='lbox network-error' v-else>
			<image class="image" src="../../static/images/img-data-error.png" mode="aspectFit"></image>
			<text class="tip">数据请求失败，请稍后再试...</text>
			<view class="btn btn-reload" @click="onReloadClick">重新加载</view>
		</view>
	</view>
</template>

<script>
	export default {
		name: "page-loadding",
		props: {
			show: {
				type: Boolean,
				default: true
			}
		},
		data() {
			return {
				statuscode: -1
			}
		},
		created() {
			this.setLoaddingTimeOut();
		},
		/**
		 * 组件的方法列表
		 */
		methods: {
			onReloadClick() {
				// this.statuscode = -1;
				// this.$emit('onReloadClick');
				// this.setLoaddingTimeOut();
				window.location.reload()
			},
			/**
			 * 错误后设置错误状态码
			 * @param {Object} statuscode
			 */
			setErrorCode: function(statuscode) {
				this.statuscode = statuscode;
			},
			setLoaddingTimeOut: function() {
				let that = this;
				setTimeout(function() {
					that.statuscode = 201;
				}, 15000);
			}
		}
	}
</script>

<style scoped>
	.loader_ image{
		width: 170rpx;
		height: 170rpx;
		margin: 0 auto;
	}
	.load {
		height: 100%;
		width: 100%;
		position: fixed;
		left: 0;
		top: 0;
		background: #FFFFFF;
		display: flex;
		justify-content: center;
		align-items: center;
		z-index: 9999;
	}

	.lbox {
		display: flex;
		flex-direction: column;
		justify-content: center;
		align-items: center;
	}

	.loader {
		border: solid 10rpx #9b59b6;
		border-right-color: transparent;
		border-left-color: transparent;
		padding: 10rpx;
		width: 100rpx;
		height: 100rpx;
		text-indent: -999920rpx;
		border-radius: 50%;
		background: #3498db;
		background-clip: content-box;
		animation: spinDisc 1.5s linear infinite;
	}

	@keyframes spinDisc {
		50% {
			border-top-color: #3498db;
			border-bottom-color: #3498db;
			background-color: #2ecc71;
		}

		100% {
			transform: rotate(1turn);
		}
	}

	.tip {
		margin-top: 20upx;
	}

	.network-error .image {
		width: 400upx;
	}

	.network-error .tip {
		color: #4c4c4c;
		font-size: 32upx;
	}

	.btn-reload {
		margin-top: 30upx;
		border: 1upx solid #D85A32;
		border-radius: 40upx;
		padding: 10upx 30upx;
		font-size: 34upx;
		color: #D85A32;
	}
</style>
